package net.begincode.convert;

import net.begincode.bean.BlogClassInfo;
import net.begincode.bean.BlogDetaiInfo;
import net.begincode.blog.bean.vo.BlogBaseInfo;
import net.begincode.blog.bean.vo.KeyWord;
import net.begincode.blog.entity.Blog;
import net.begincode.common.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

public class BlogConvertUtils {
    public static BlogDetaiInfo convert(Blog blog,List<KeyWord> blogKeys){
        BlogDetaiInfo blogDetaiInfo  = new BlogDetaiInfo();
        blogDetaiInfo.setBlogId(blog.getId());
        blogDetaiInfo.setBlogTitle(blog.getBlogTitle());
        blogDetaiInfo.setBlogAbstract(blog.getBlogAbstract());
        blogDetaiInfo.setBlogContent(blog.getBlogContent());
        blogDetaiInfo.setKeys(blogKeys);
        blogDetaiInfo.setBlogContent(blog.getBlogContent());
        blogDetaiInfo.setLowCount(blog.getLowCount());
        blogDetaiInfo.setPraiseCount(blog.getPraiseCount());
        blogDetaiInfo.setcDate(blog.getCdate());
        blogDetaiInfo.setViews(blog.getViews());
        blogDetaiInfo.setUserId(blog.getUserId());
        return blogDetaiInfo;
    }

    public static List<BlogClassInfo> convert(List<Blog> blogs){
       return CollectionUtils.safes(blogs).stream().map(BlogConvertUtils::convert)
                .collect(Collectors.toList());
    }

    public static BlogClassInfo convert(Blog blog){
        BlogClassInfo blogClassInfo = new BlogClassInfo();
        blogClassInfo.setBlogId(blog.getId());
        blogClassInfo.setBlogTitle(blog.getBlogTitle());
        blogClassInfo.setcDate(blog.getCdate());
        blogClassInfo.setViews(blog.getViews());
        blogClassInfo.setBlogAbstract(blog.getBlogAbstract());
        return blogClassInfo;
    }

    public static List<BlogBaseInfo> convertBlogs(List<Blog> blogs){
        return CollectionUtils.safes(blogs).stream().map(BlogConvertUtils::convertBlog)
                .collect(Collectors.toList());
    }

    public static BlogBaseInfo convertBlog(Blog blog){
        BlogBaseInfo blogBaseInfo = new BlogBaseInfo();
        blogBaseInfo.setBlogId(blog.getId());
        blogBaseInfo.setBlogTitle(blog.getBlogTitle());
        blogBaseInfo.setViews(blog.getViews());
        return blogBaseInfo;
    }

}
